#include "picketdrawablebuilder.h"
#include "db/dbconnection.h"

PicketDrawableBuilder::PicketDrawableBuilder()
{
}

void PicketDrawableBuilder::_createDrawableFromRecord(QSqlRecord record, QMap<QString, Drawable *> &map)
{
    QVariant x = record.value("x");
    QVariant y = record.value("y");
    PicketDrawable *picket = new PicketDrawable(QPointF(x.toDouble(), y.toDouble()));
    picket->setTag(this->_globalId);
    map.insert(record.value("idPicket").toString(), picket);
}

QMap<QString, Drawable *> PicketDrawableBuilder::build()
{
    QMap<QString, Drawable *> map;

    if(!_model.isNull())
    {
        _model->setFilter(_modelFilter);
        _model->select();
        for(int i=0; i<_model->rowCount(); i++)
        {
            QSqlRecord rec = _model->record(i);
            _createDrawableFromRecord(rec, map);
        }
    }
    else
    {
        _createDrawableFromRecord(_rowRecord[0], map);
    }
    return map;
}


